function is_pc(){
// 其他类型的移动操作系统类型，自行添加
    var os = new Array("Android","iPhone","Windows Phone","iPod","iPad","BlackBerry","MeeGo","SymbianOS","Chrome","Firefox");
    var info = navigator.userAgent;
    var len = os.length;
    for (var i = 0; i < len; i++) {
        if (info.indexOf(os[i]) > 0){
            return false;
        }
    }
    return true;
}

//点击出二维码
$(function(){
    $(".btn-twocode").hover(function(){
        $(".twocode").slideToggle(80);
    })
});

//控制背景视频
function resizeVideo(){
    var $winW = $(window).width(),
        $winH = $(window).height(),
        $video = $("#video_player"),
        $videoW = $winH*1.77777,
        $videoH = $winW/1.77777,
        $rad = $winW/$winH,
        $left = ($videoW-$winW)/2;
    $top = ($videoH-$winH)/2;
    if($rad > 1.777){
        $video.css({width:$winW+'px',height:$videoH+'px',top:-$top+'px',left:0});
    }else{
        $video.css({width:$videoW+'px',height:$winH+'px',left:-$left+'px',top:0});
    }
}
resizeVideo();

//弹出大图
function scrollimg(curnum){
    var num = $('#imglist li').length,
        imgW = $('#imglist li').eq(0).width(),
        allW = imgW*num;
    $('#imglist').css({width:allW +'px'});
    if(curnum > -1){
        scrW = imgW*curnum;
        $('#btnleft').attr({'data-url':curnum-1});
        $('#btnright').attr({'data-url':parseInt(curnum)+1});
        $('#imglist').animate({left:-scrW +'px'});
    }
}
//视频切换
function scrollvideo(tab,obj,curnum){
    var num = $('#'+obj+' li').length,
        imgW = $('#'+obj+' li').eq(0).width(),
        allW = imgW*num;
    $('#'+obj+'').css({width:allW +'px'});
    scrW = imgW*curnum;
    $('#'+obj+'').animate({'marginLeft':-scrW +'px'},200);
    $('#'+tab+'').removeClass();
    $('#'+tab+'').addClass('tab-'+curnum);
}

//字幕滚动
var maquee = (function(){
    var maquee = document.getElementById("maquee"),
        maquee_ul = document.getElementById("caption"),
        maquee_li = maquee_ul.getElementsByTagName("p"),
        wid = 0;

    // 复制两份子元素防止内容不够出现空白
    len = maquee_li.length;
    for(var i=0;i<len;i++){
        maquee_ul.appendChild(maquee_ul.children[i].cloneNode(true));
    }
    for(var i=0;i<len;i++){
        maquee_ul.appendChild(maquee_ul.children[i].cloneNode(true));
    }
    var hig = maquee_ul.offsetHeight;

    var rolling = function(){
        if(cutPx(maquee_ul.style.marginTop) == -parseInt(hig*3)){
            maquee_ul.style.marginTop = 0;
        }else{
            maquee_ul.style.marginTop = (cutPx(maquee_ul.style.marginTop) - 1) + "px";
        }
    }

    var timer = setInterval(rolling, 50);
    maquee.onmouseover = function(){
        clearInterval(timer);
        timer = null;
    }
    maquee.onmouseout = function(){
        if(!timer){
            timer = setInterval(rolling, 50);
        }
    }
    // 去掉marginLeft单位
    function cutPx(str){
        return +str.slice(0,-2);
    }
});

$(function(){
    $('#manlist li').click(function(){
        _paq.push(['trackLink', 'people'+$(this).index(), 'ck_id']);//统计
        $('.popwin').show();
        open_mask();
        scrollimg($(this).index());
    });

    $('#btnleft').click(function(){
        var attr = $(this).attr('data-url');
        if(attr < 0){
            $(this).css({opacity:.5});
            return;
        }
        $('#btnright').css({opacity:1});
        scrollimg(attr);
    });

    $('#btnright').click(function(){
        var attr = $(this).attr('data-url');
        if(attr > 8){
            $(this).css({opacity:.5});
            return;
        }
        $('#btnleft').css({opacity:1});
        scrollimg(attr);
    });

    $('#btnclose').click(function(){
        $('.popwin').css({display:'none'});
        close_mask();
    });

    //第二屏视频
    $('#vtab li').click(function(){
        scrollvideo('vtab','vlist',$(this).index());
    });

    //第三屏视频
    $('#vtab2 li').click(function(){
        scrollvideo('vtab2','vlist2',$(this).index());
    });

    //背景视频重播
    $('#btnplay').click(function(){
        $('#video_player')[0].play();
        $('#poster').animate({opacity:0},500);
        $(this).hide();
    });

    //音频字幕
    $('#btnmusic').click(function(){
        $('#caption').animate({opacity:1},800);
        $(this).hide();
    });
    $('#playOrPause').click(function(){
        $('#caption').animate({opacity:1},800);
        $('#btnmusic').hide();
        maquee();
    });
});

//鼠标移动背景
function move(obj,mobj){
    var middleX = obj.clientWidth / 2;
    var middleY = obj.clientHeight / 2;
    var flagX = 0,
        flagY = 0,
        screenX, screenY,
        positionX, positionY;
    screenX = event.screenX;
    screenY = event.screenY;
    var valueX = screenX - middleX,
        valueY = screenY - middleY;
    if( valueX < 0){
        flagX = 1;
    }
    if( valueY < 0){
        flagY = 1;
    }
    positionX = Math.pow(flagX == 0 ? valueX : -valueX, 1/2.5);
    positionY = Math.pow(flagY == 0 ? valueY : -valueY, 1/2.5);
    if(flagX == 0){
        positionX = -positionX;
    }
    if(flagY == 0){
        positionY = -positionY;
    }
    mobj.style.transition = 'none';
    mobj.style.webkitTransform = 'translate3d('+positionX+'px,'+positionY+'px,0)';
    flagX = 0;
    flagY = 0;
}
if($('#mobile')[0].addEventListener){
    $('#mobile')[0].addEventListener('mousemove',function(){move($('#mobile')[0],$('#triangle')[0])},false);
    $('#page3')[0].addEventListener('mousemove',function(){move($('#page3')[0],$('#tatter')[0])},false);
}else{
    $('#mobile')[0].attachEvent('mousemove',function(){move($('#mobile')[0],$('#triangle')[0])});
    $('#page3')[0].attachEvent('mousemove',function(){move($('#page3')[0],$('#tatter')[0])});
}


//视频弹窗
var mask = document.getElementById("ucmask");
document.getElementById("video_win_close").onclick = function(){
    close_mask();
    closeWin('video_win');
    document.getElementById("video_win_html").innerHTML ="";
}

function closeWin(o){
    var dom = document.getElementById(o);
    dom.style.display = "none";
    document.getElementById("video_win_html").innerHTML ="";
}
//打开弹出窗
function openWin(o){
    var dom = document.getElementById(o);
    if(!dom){return;}
    open_mask();
    dom.style.display = "block";
    resizeWin(o);
}
//改变弹出窗
function resizeWin(o){
    var dom = document.getElementById(o);
    var h = document.documentElement.clientHeight;
    var top = document.documentElement.scrollTop || document.body.scrollTop;
    var w = document.documentElement.offsetWidth;
    if(!dom){return;}
    var scroller,scrollbar;

    //open_mask();
    switch(o){
        case "video_win":{
            dom.style.width = "680px";
            dom.style.height = "500px";
            dom.style.top = (h - dom.offsetHeight)/2 +top +"px";
            dom.style.left = (w- dom.offsetWidth)/2 +"px";
            break;
        }
    }
}

//显示遮罩
function open_mask(){
    mask.style.width = document.documentElement.offsetWidth+"px";
    mask.style.height = (document.body.clientHeight>document.documentElement.clientHeight?document.body.clientHeight:document.documentElement.clientHeight)+"px";
}
//关闭遮罩
function close_mask(){
    mask.style.cssText ="";
    document.body.parentNode.style.cssresizeWinText = "padding:0;overflow:scroll;";
}

window.onresize = function(){
    resizeWin("video_win");
    resizeVideo();
}

function loadVideo(name,title,path){
    document.getElementById("video_title").innerHTML = title;
    if(is_pc()){
        document.getElementById("video_win_html").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="360" id="FLVPlayer">			  <param name="movie"value="video/FLVPlayer_Progressive.swf" />			  <param name="quality" value="high" />			  <param name="wmode" value="opaque" />			  <param name="scale" value="noscale" />			  <param name="salign" value="lt" />			  <param name="FlashVars"value="&amp;MM_ComponentVersion=1&amp;skinName=video/Clear_Skin_2&amp;streamName='+name+'&amp;autoPlay=true&amp;autoRewind=false" />			  <paramname="swfversion" value="8,0,0,0" /><!--[if !IE]>--> <object type="application/x-shockwave-flash" data="video/FLVPlayer_Progressive.swf" width="640" height="360"><!--<![endif]--><param name="quality" value="high" />				<param name="wmode" value="opaque" />				<param name="scale" value="noscale" />				<param name="salign" value="lt" />				<param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=video/Clear_Skin_2&amp;streamName='+name+'&amp;autoPlay=true&amp;autoRewind=false" />				<param name="swfversion" value="8,0,0,0" />				<param name="expressinstall" value="'+name+'.flv" /><PARAM NAME="wmode" VALUE="transparent">				<!--[if !IE]>-->			  </object>			  <!--<![endif]-->			</object>';
    }else{
        document.getElementById("video_win_html").innerHTML = '<video width="640" height="360" src="http://image.uc.cn/s/uae/g/01/'+path+'/'+name+'.mp4" autoPlay controls></video>'
    }
}

//阻止事件冒泡
function estop(e){
    var e=arguments.callee.caller.arguments[0]||event;
    if (e && e.stopPropagation){
        //因此它支持W3C的stopPropagation()方法
        e.stopPropagation();
    }else{
        //否则，我们需要使用IE的方式来取消事件冒泡
        window.event.cancelBubble = true;
        return false;
    }
}/**
 * Created by lenovo on 2016/6/25.
 */
